/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 12/25/13
 * Time: 8:53 PM
 * To change this template use File | Settings | File Templates.
 */
package societyGames.dataFunctions
{
import flash.events.EventDispatcher;
import flash.utils.Dictionary;

public class DataFunctionStorage extends EventDispatcher
{
  private static var _instance:DataFunctionStorage = new DataFunctionStorage();

  public static function get instance():DataFunctionStorage
  {
    return _instance;
  }

  private var _values:Dictionary = new Dictionary(); //name:String, value:Object
  private var _arrayValues:Dictionary = new Dictionary(); //name:String, values:Array;

  public function setValue(name:String, value:Object):Object
  {
    _values[name] = value;
    return value;
  }

  public function getValue(name:String):Object
  {
    return _values[name];
  }

  public function setArrayValue(name:String, index:int, value:Object):Object
  {
    var values:Array;
    if (_arrayValues.hasOwnProperty(name))
    {
      values = _arrayValues[name];
    }
    else
    {
      values = new Array();
    }

    values[index] = value;
    return value;
  }

  public function getArrayValue(name:String, index:int):Object
  {
    if (!_arrayValues.hasOwnProperty(name))
    {
      return null;
    }
    var values:Array = _arrayValues[name];
    return values[index];
  }

  public function getArrayCount(name:String):int
  {
    if (!_arrayValues.hasOwnProperty(name))
    {
      return 0;
    }
    var values:Array = _arrayValues[name];
    return values.count;
  }
}
}
